package com.timothy.junk;

import java.util.ArrayList;
import java.util.HashMap;

import com.timothy.junk.R;
import com.timothy.gfund.activity.RepoHome;
import com.timothy.junk.cbond.activity.CBondHome;
import com.timothy.junk.gfund.activity.GFundHome;
import com.timothy.junk.tfund.activity.TFundHome;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.SimpleAdapter;

public class JunkHome extends Activity {

	Context mContext;
	String[] junks;
	
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.junk_home);
        
        mContext = getApplicationContext();
        
        GridView gridview = (GridView) findViewById(R.id.gridview);
        
        junks = this.getResources().getStringArray(R.array.junks);
        
        ArrayList<HashMap<String, Object>> lstImageItem = new ArrayList<HashMap<String, Object>>();
        for(int i=0;i<junks.length;i++){
        	HashMap<String, Object> map = new HashMap<String, Object>();
        	map.put("ItemImage", R.drawable.icon);
			map.put("ItemText", junks[i]);
        	lstImageItem.add(map);
        }
        
		SimpleAdapter saImageItems = new SimpleAdapter(this, lstImageItem,
				R.layout.junk_home_item, new String[] { "ItemImage","ItemText" },
				new int[] { R.id.ItemImage, R.id.ItemText });
		
        gridview.setAdapter(saImageItems);
        
        gridview.setOnItemClickListener(new ItemClickListener());
    }
    
    class  ItemClickListener implements OnItemClickListener{
		@Override
		public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			HashMap<String, Object> item=(HashMap<String, Object>) arg0.getItemAtPosition(arg2);
			setTitle((String)item.get("ItemText"));
			
			switch(arg2){
				 case 0:go2GFundHome();break;
				 case 1:go2TFundHome();break;
				 case 2:go2CBondHome();break;
				 case 3:go2RepoHome();break;
			}

		}
    }
    public void go2GFundHome(){
		Intent intent=new Intent(mContext, GFundHome.class);
		startActivity(intent);    	
    }
    
    public void go2TFundHome(){
		Intent intent=new Intent(mContext, TFundHome.class);
		startActivity(intent);    	
    }
    
    public void go2CBondHome(){
		Intent intent=new Intent(mContext, CBondHome.class);
		startActivity(intent);    	
    }
    
    public void go2RepoHome(){
		Intent intent=new Intent(mContext, RepoHome.class);
		startActivity(intent);    	
    }
    
}
